package shopcart;

import java.util.Scanner;

public class shopcart {
    public static void main(String[] args) {
    
    Good[] arr = new Good[5];
    Good g1 = new Good("苹果", 1000, 2.5F, "红苹果，黄苹果");
    Good g2 = new Good("香蕉", 1000, 1.5F, "大香蕉，小香蕉");
    Good g3 = new Good("可乐", 1000, 3.5F, "无糖可乐，可乐");
    Good g4 = new Good("雪碧", 1000, 4.5F, "无糖雪碧，雪碧");
    Good g5 = new Good("梨", 1000, 5.5F, "福梨，鸭梨，呆梨");

    arr[0] = g1;
    arr[1] = g2;
    arr[2] = g3;
    arr[3] = g4;
    arr[4] = g5;

    for (int i = 0; i < arr.length; i++) {
        Good good = arr[i];
        System.out.println(good.getName() + " " + good.getNumber() + " " + good.getPrice() + " " + good.getkind());
    }

    Scanner sc = new Scanner(System.in);
    System.out.println("您的购物车仅能容纳三件商品");
    double single=0;
    String []total_good=new String[3];
    String []total_kind=new String[3];
    double[]total=new double[3];
    int j=0;
    while(j<3) {
        boolean result=false;
        System.out.println("请输入你想购买的物品");
        String yours_good = sc.nextLine();

        for (int i = 0; i < arr.length; i++) {
            if (yours_good.equals(arr[i].getName())) {
                result =true;
                System.out.println("请输入你想购买物品的种类");
                String yours_kind = sc.nextLine();

                System.out.println("请输入你想购买物品的数量");
                int number = sc.nextInt();
                sc.nextLine();

                single = number * arr[i].getPrice();

                total_good[j] = yours_good;
                total_kind[j] = yours_kind;
                total[j] = single;

                j++;


                break;
            }
        }
        System.out.println("如果您已购买完毕请输入1，否则输入0");
        int end=sc.nextInt();
        sc.nextLine();
        if(end==1)
            break;
        if(!result) {
            System.out.println("本店无该商品");


        }
    }
    System.out.println("购物车内容：");
    for (int i = 0; i < j; i++) {
        System.out.println("第" + i + "件商品名称：" + total_good[i] + "，种类：" + total_kind[i] + "，总价：" + total[i]);
    }
    int sum=0;
    for (int k = 0; k <3 ; k++) {
        sum+=total[k];
    }
    System.out.println(sum);
    System.out.println("如果您要删除购物车中的某商品");
    System.out.println("删除第一件商品请输入1，删除第二件商品请输入2，删除第三件商品请输入3，不需要请输入4");
    int delete=sc.nextInt();
    switch (delete){
        case 1:total_good[0]="无";total_kind[0]="无";total[0]=0;break;
        case 2:total_good[1]="无";total_kind[1]="无";total[1]=0;break;
        case 3:total_good[2]="无";total_kind[2]="无";total[2]=0;break;
        default:break;
    }
    int sum2=0;
    for (int k = 0; k <3 ; k++) {
        sum2+=total[k];
    }
    System.out.println("您需要支付"+sum2+"元");
    sc.close();
}
}
